package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;


    /**
     * 根据手机号码查询数据库
     * @param phoneNumber
     * @return
     */
    public User selectByPhoneNumber(String phoneNumber) {

        //1.构造查询条件
        QueryWrapper<User> qw =new QueryWrapper<>();
        qw.eq("mobile", phoneNumber);
        //2.根据手机号码查询用户
        User user = userMapper.selectOne(qw);
        return user;
    }


    /**
     * 添加新用户
     * @param user
     */
    @Override
    public Long addNewUser(User user) {
        userMapper.insert(user);
        Long userId = user.getId();
        return userId;
    }

    //保存新的手机号
    @Override
    public void updateUserPhone(User user) {
        userMapper.updateById(user);
    }

    //根据用户id修改用户信息
    public void update(User user) {
        userMapper.updateById(user);
    }

    //根据用户id查找用户
    public User queryUserById(Long userId) {
        return userMapper.selectById(userId);
    }

    //1.根据环信id查询用户
    public User queryUserByHuanXin(String huanxinId) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("hx_user",huanxinId);
        User user = userMapper.selectOne(qw);
        return user;
    }
}
